package gui.sejour;

import gui.FenetrePrincipale;
import gui.PanelClient;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.ListSelectionModel;

import Controleur.ControleurSejour;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import main.GestionnaireReservation;

public class FenetreConfirmationSejour extends FenetrePrincipale {
	private JLabel lblNumConfirmation;
	private PanelClient client;
	private JList lstSejour;
	private JButton btnTerminer;
	
	public FenetreConfirmationSejour(ActionListener ctrl){
		super();
		
		afficher(ctrl);
	}
	
	@Override
	public void afficher(final ActionListener ctrl) {
		setTitle("Confirmation de s\u00E9jour");
		setSize(508, 510);
		init();
		
		getContentPane().setLayout(null);
		
		JLabel lblConfirmationPourRservation = new JLabel("Confirmation pour r\u00E9servation #");
		lblConfirmationPourRservation.setBounds(12, 13, 208, 16);
		getContentPane().add(lblConfirmationPourRservation);
		
		lblNumConfirmation = new JLabel("#conf");
		lblNumConfirmation.setBounds(211, 13, 56, 16);
		getContentPane().add(lblNumConfirmation);
		
		client = new PanelClient();
		client.fillWithClient(GestionnaireReservation.getClient());
		client.setLocation(0, 43);
		getContentPane().add(client);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 244, 469, 130);
		getContentPane().add(scrollPane);
		
		lstSejour = new JList();
		lstSejour.setListData(((ControleurSejour)ctrl).getListSejour().toArray());
		lstSejour.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		lstSejour.addListSelectionListener(new ListSelectionListener() {
			
			@Override
			public void valueChanged(ListSelectionEvent arg0) {
				if (lstSejour.getSelectedIndex() >= 0) {
					ctrl.actionPerformed(new ActionEvent(this, lstSejour.getSelectedIndex(), 
							String.valueOf(ControleurSejour.MODIFIER_SEJOUR)));
				}
			}
		});
		scrollPane.setViewportView(lstSejour);
		
		JLabel lblRemettreLesCls = new JLabel("Remettre les cl\u00E9s au client.");
		lblRemettreLesCls.setBounds(12, 387, 467, 16);
		getContentPane().add(lblRemettreLesCls);
		
		JPanel pnlBouton = new JPanel();
		pnlBouton.setBounds(12, 418, 466, 45);
		getContentPane().add(pnlBouton);
		
		btnTerminer = new JButton("Terminer");
		pnlBouton.add(btnTerminer);
		btnTerminer.addActionListener (ctrl);
		btnTerminer.setActionCommand(String.valueOf(ControleurSejour.CONFIRMATION_SEJOUR));
		
		setVisible(true);
	}
}
